package com.atguigu.secutirydemo.controller;

import com.atguigu.secutirydemo.entity.User;
import com.atguigu.secutirydemo.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: UserController
 * Package:
 * Description:
 *
 * @Author:xiaohei
 * @Create 2025/2/4 17:36
 * Version 1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    public UserService userService;

    @GetMapping("/list")
    @PreAuthorize("hasRole('ADMIN')")
    public List<User> getList(){
        return userService.list();
    }

    @PostMapping("/add")
    @PreAuthorize("hasRole('USER')")
    public void add(@RequestBody User user){
        userService.saveUserDetails(user);
    }
}
